package com.gagakuai.executor.result;

import com.gagakuai.reflect.factory.ObjectFactory;
import com.gagakuai.session.ResultContext;
import com.gagakuai.session.ResultHandler;

import java.util.ArrayList;
import java.util.List;

/*
 * @program: common-starters
 * @description: 默认的结果处理器
 * @author: houhong
 * @create: 2023-06-29 21:32
 */
public class DefaultResultHandler<T> implements ResultHandler<Object> {

    private final List<Object> list;

    public DefaultResultHandler() {
        list = new ArrayList<>();
    }

    @SuppressWarnings("unchecked")
    public DefaultResultHandler(ObjectFactory objectFactory) {
        list = objectFactory.create(List.class);
    }

    @Override
    public void handleResult(ResultContext<? extends Object> context) {
        list.add(context.getResultObject());
    }

    public List<Object> getResultList() {
        return list;
    }
}